<include file="../header" />
<div class="wrapper white-bg">
    <div>
        <img src="/assets/repaireast/images/header.jpg" alt="">
    </div>
    <div class="content">
        <div class="list flex">
            <div class="icon iconfont icon-iconfontxingming"></div>
            <input class="input" type="text" placeholder="请输入姓名" id="user_name">
        </div>
        <div class="list flex">
            <div class="icon iconfont icon-mima"></div>
            <input class="input flex-1" type="text" placeholder="请输入手机号码" id="mobile">
            <a href="#" class="blue send show">发送验证码</a>
        </div>
        <div class="list flex">
            <div class="icon iconfont icon-mima"></div>
            <input class="input" type="text" placeholder="请输入验证码" id="code">
        </div>
    </div>
    <a href="#" class="btn text-center" id="login">登录</a>
    <input type="hidden" id="is_submit" value="0">
    <input type="hidden" id="url" value="{BEESCRM:$url}">
</div>
<script src="/assets/repaireast/js/layer.js"></script>
<script src="/assets/repaireast/js/public.js"></script>
<script>
    //点击获取验证码
    var verifyTag = true;
    $('.list').on('click', '.send', function (e) {
        var mobile = $('#mobile').val();
        if (!mobile){
            fm.alert('手机号不能为空！');
            return false;
        }
        var reg = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
        if(!reg.test(mobile)){
            fm.alert('手机号格式有误！');
            return false;
        }
        e.preventDefault();
        if(verifyTag) {
            $.ajax({
                type:'post',
                url:"/Repaireast/Repaireast/sendText",
                dataType:'json',
                data:{
                    'mobile' : mobile
                },
                success:function(data){}
            });
            timeCountDown(this);
        }
    });
    // 验证倒计时
    function timeCountDown(elem, seconds) {
        verifyTag = false;
        if(typeof seconds == undefined || seconds == null) seconds = 60;
        setTimeout(function () {
            if(seconds > 0) {
                seconds--;
                $(elem).text('已发送 ' + seconds + 's').addClass('time');
                timeCountDown(elem, seconds);
            } else {
                $(elem).removeClass('time').text('获取验证码');
                verifyTag = true;
            }
        }, 1000);
    }

    $('#login').click(function(){
        var user_name = $('#user_name').val();
        if (!user_name){
            fm.alert('姓名不能为空！');
            return false;
        }
        var mobile = $('#mobile').val();
        if (!mobile){
            fm.alert('手机号不能为空！');
            return false;
        }
        var reg = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
        if(!reg.test(mobile)){
            fm.alert('手机号格式有误！');
            return false;
        }
        var code = $('#code').val();
        if (!code){
            fm.alert('验证码不能为空！');
            return false;
        }

        //防止重复提交
        var is_submit = $('#is_submit').val();
        if (is_submit == 0){
            $('#is_submit').val(1);
            $.ajax({
                type:'post',
                url:"/Repaireast/Repaireast/doRegister",
                dataType:'json',
                data:{
                    'user_name' : user_name,
                    'mobile' : mobile,
                    'code' : code,
                    'url' : $('#url').val()
                },
                success:function(data){
                    if(data.status=='S'){
                        fm.alert('登陆成功!');
                        setTimeout(function(){
                            window.location.href=data.url;
                        },2000);
                    }else{
                        fm.alert(data.message);
                    }
                    $('#is_submit').val(0);
                },
                error:function(){
                    fm.alert('通讯失败，请稍后再试');
                    $('#is_submit').val(0);
                }
            });
        }
    });
</script>
<include file="../footer" />